﻿<%@ Page Language="C#" MasterPageFile="~/TestSystem/TestSystemMain.Master" AutoEventWireup="true" ValidateRequest="false" Inherits="Admin_ManageSubjects" Title="Untitled Page" Codebehind="ManageSubjects.aspx.cs" %>

<asp:Content ID="MngSubjects" ContentPlaceHolderID="TsContent" Runat="Server">
<div class="admin-panel">
    <asp:ListView runat="server" ID="lvwSubjects" DataKeyNames="SubjectID" ConvertEmptyStringToNull="true" 
        InsertItemPosition="LastItem" DataSourceID="subjectsObjSource" 
        onitemcommand="lvwSubjects_ItemCommand" 
        onitemdeleted="lvwSubjects_ItemDeleted" 
        oniteminserted="lvwSubjects_ItemInserted"
        onitemupdating="lvwSubjects_ItemUpdating" >
        <LayoutTemplate>
            <div class="command-buttons">
                <a style="padding-left:10px;" href="#insert">Новий предмет</a>
            </div>
            <div style="padding-left:10px;">
                <asp:DataPager ID="pager1" PageSize="10" runat="server">
                    <Fields><asp:NumericPagerField /></Fields>
                </asp:DataPager>
            </div>
            <div ID="itemPlaceholder" runat="server">
            </div>
            <div style="padding-left:10px;">
                <asp:DataPager ID="pager2" PageSize="10" runat="server">
                    <Fields><asp:NumericPagerField /></Fields>
                </asp:DataPager>
            </div>
        </LayoutTemplate>
        <ItemTemplate>
            <div class="item-div">
                <div class="item">
                <table>
                <tr>
                    <td><p><span id="Span1" runat="server" visible='<%# Eval("Deleted") %>' class="item-removed">&nbsp;(видалено)</span></p></td>
                </tr>   
                <tr>
                    <td><%# Eval("SubjectName") %></td>
                </tr> 
                <tr>
                    <td><p><%# Eval("Description") %></p></td>
                </tr> 
                <tr>
                    <td>
                        <div class="command-buttons">
                            <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" CssClass="command-button" Text="Редагувати"></asp:LinkButton>
                            <asp:LinkButton ID="btnDelete" runat="server" CommandName="Delete" CssClass="command-button" Text="Видалити"
                             OnClientClick="return confirm('Ви впевнені, що хочете видалити даний предмет ?') == true"></asp:LinkButton>
                            <asp:LinkButton ID="btnRestore" runat="server" CommandArgument='<%# Eval("SubjectID") %>' CommandName="Restore" CssClass="command-button" Text="Відновити" Visible='<%# Eval("Deleted") %>'></asp:LinkButton>
                            <asp:LinkButton ID="btnAllQuizes" runat="server" CommandName="ShowAllQuizes" CssClass="command-button" Text="Тести" CommandArgument='<%# Eval("SubjectID") %>'></asp:LinkButton>
                            <asp:LinkButton ID="btnAddQuiz" runat="server" CommandName="AddQuiz" CssClass="command-button" Text="Додати тест" CommandArgument='<%# Eval("SubjectID") %>'></asp:LinkButton>
                        </div>
                    </td>
                </tr>
                </table>
                </div>
            </div>
        </ItemTemplate>
        <EditItemTemplate>
            <div class="edititem-div">
                <div class="item">
                <table>
                    <tr>
                        <td><span class="prop-label">Назва предмету:</span></td>
                        <td><asp:TextBox runat="server" ID="txtName1" CssClass="txtMedium" Text='<%# Bind("SubjectName") %>'  ValidationGroup="edit"></asp:TextBox></td>
                        <td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName1" ErrorMessage="Необхідно ввести назву предмету" ValidationGroup="edit">*</asp:RequiredFieldValidator></td>
                    </tr>
                    <tr>
                        <td><span class="prop-label">Опис:</span></td>
                        <td><asp:TextBox runat="server" ID="txtDesc1"  TextMode="MultiLine" Text='<%# Bind("Description") %>' ValidationGroup="edit"></asp:TextBox></td>
                    </tr>
                    <tr>
                    <td>
                        <div id="validation-summary">
                            <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Виправте наступні помилки:" DisplayMode="List" ShowSummary="true" ValidationGroup="edit" />
                        </div>
                    </td>
                    </tr>
                    <tr>
                    <td>
                        <div class="command-buttons">
                            <asp:LinkButton ID="btnUpdate" runat="server" CommandName="Update" CssClass="command-button" Text="Оновити" ValidationGroup="edit" />
                            <asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" CssClass="command-button" Text="Відмінити" />
                        </div>
                    </td>
                    </tr>
                </table>
                </div>
            </div>
        </EditItemTemplate>
        <InsertItemTemplate>
            <div class="item-div">
                <div class="item">
                    <a id="insert"></a>
                    <p><span class="prop-label">Назва предмету:</span>
                    <asp:TextBox runat="server" ID="txtName2" CssClass="txtMedium"  Text='<%# Bind("SubjectName") %>' MaxLength="50" ValidationGroup="insert"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtName2" ErrorMessage="Необхідно ввести назву предмету" ValidationGroup="insert">*</asp:RequiredFieldValidator>
                    </p>
                    <p><span class="prop-label">Опис:</span>
                    <asp:TextBox runat="server" ID="txtDesc2" TextMode="MultiLine" Text='<%# Bind("Description") %>' ValidationGroup="insert" ></asp:TextBox>
                    </p>
                    <div id="validation-summary">
                        <asp:ValidationSummary ID="ValidationSummary2" runat="server" HeaderText="Виправте наступні помилки:" DisplayMode="List" ValidationGroup="insert" />
                    </div>
                    <div class="command-buttons">
                        <asp:LinkButton ID="btnInsert" runat="server" CommandName="Insert" CssClass="command-button" Text="Додати" ValidationGroup="insert" />
                        <asp:LinkButton ID="btnCancel" runat="server" CommandName="Cancel" CssClass="command-button" Text="Відмінити" />
                    </div>
                </div>
            </div>
        </InsertItemTemplate>
    </asp:ListView>
    
    <asp:ObjectDataSource ID="subjectsObjSource" runat="server" EnablePaging="true" SelectCountMethod="GetCount" DeleteMethod="Remove" InsertMethod="Add" SelectMethod="GetAll" 
        TypeName="TestSystem.BLL.TestSystem.Subject">
        <DeleteParameters>
            <asp:Parameter Name="subjectID" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="subjectName" Type="String" />
            <asp:Parameter Name="description" Type="String" />
        </InsertParameters>
    </asp:ObjectDataSource>
</div>
</asp:Content>

